package com.example.plat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.plat.enity.Activity;
import com.example.plat.exception.AdminException;
import com.example.plat.mapper.AdminMapper;
import com.example.plat.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {


    @Autowired
    private AdminMapper mapper;

    @Override
    public IPage<Activity> getJudge(Integer pageNum, Integer pageSize){
        Page<Activity> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Activity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Activity::getIsPass,false);
        mapper.selectPage(page,lqw);
        return page;
    }

    @Override
    public IPage<Activity> getPass(Integer pageNum, Integer pageSize) {
        Page<Activity> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Activity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Activity::getIsPass,true);
        mapper.selectPage(page,lqw);
        return page;
    }


    @Override
    public Boolean judgeActivity(Long actId, boolean isPass)throws AdminException {
        try{
            mapper.judgeActivity(actId,isPass?1:0);
        }catch (Exception e){
            throw new AdminException("审核活动失败！");
        }
        return true;
    }
}
